home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWAbout.cpp next >
Encoding:
Text File  |  1996-09-17  |  12.1 KB  |  405 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWAbout.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWABOUT_H
  11. #include "FWAbout.h"
  12. #endif
  13.  
  14. #ifndef FWPART_K
  15. #include "FWPart.k"
  16. #endif
  17.  
  18. #ifndef FWPART_H
  19. #include "FWPart.h"
  20. #endif
  21.  
  22. #ifndef FWCONTXT_H
  23. #include "FWContxt.h"
  24. #endif
  25.  
  26. #ifndef FWICONSH_H
  27. #include "FWIconSh.h"
  28. #endif
  29.  
  30. #ifndef FWLINSHP_H
  31. #include "FWLinShp.h"
  32. #endif
  33.  
  34. #ifndef FWRESACC_H
  35. #include "FWResAcc.h"
  36. #endif
  37.  
  38. #ifndef FWRESSIN_H
  39. #include "FWResSin.h"
  40. #endif
  41.  
  42. #ifndef FWCFMRES_H
  43. #include "FWCFMRes.h"
  44. #endif
  45.  
  46. #ifndef FWMEMMGR_H
  47. #include "FWMemMgr.h"
  48. #endif
  49.  
  50. #ifndef FWTXTSHP_H
  51. #include "FWTxtShp.h"
  52. #endif
  53.  
  54. #ifndef FWTXTBOX_H
  55. #include "FWTxtBox.h"
  56. #endif
  57.  
  58. #ifndef FWMNUBAR_H
  59. #include "FWMnuBar.h"
  60. #endif
  61.  
  62. #ifndef SLODFSTR_H
  63. #include "SLODFStr.h"
  64. #endif
  65.  
  66. #ifndef SLODFSTR_K
  67. #include "SLODFStr.k"
  68. #endif
  69.  
  70. #ifndef FWSESION_H
  71. #include "FWSesion.h"
  72. #endif
  73.  
  74. // ----- OpenDoc Includes -----
  75.  
  76. #ifndef SOM_ODFacet_xh
  77. #include <Facet.xh>
  78. #endif
  79.  
  80. //========================================================================================
  81. // Runtime Informations
  82. //========================================================================================
  83.  
  84. #ifdef FW_BUILD_MAC
  85. #pragma segment fwabout
  86. #endif
  87.  
  88. FW_DEFINE_AUTO(FW_CAboutFrame)
  89.  
  90. //========================================================================================
  91. // Constants for this module
  92. //========================================================================================
  93.  
  94. const ODID kOKButtonID = 1;
  95.  
  96. const FW_Fixed kDialogWidth         = FW_IntToFixed(350);
  97. const FW_Fixed kDialogHeight         = FW_IntToFixed(250);
  98. const FW_Fixed kLargeMargin         = FW_IntToFixed(20);
  99. const FW_Fixed kSmallMargin         = FW_IntToFixed(10);
  100. const FW_Fixed kIconSize             = FW_IntToFixed(32);
  101.  
  102. const FW_Fixed kButtonWidth         = FW_IntToFixed(80);
  103. const FW_Fixed kButtonHeight         = FW_IntToFixed(30);
  104.  
  105. const FW_Fixed kCopyrightHeight     = FW_IntToFixed(30);
  106. const FW_Fixed kDescriptionHeight     = FW_IntToFixed(200);
  107.  
  108. //========================================================================================
  109. // FW_About 
  110. //========================================================================================
  111.  
  112. void FW_About(Environment* ev, FW_CPart* part, FW_ResourceID id)
  113. {
  114.     FW_CPresentation* aboutDialogPresentation = NULL;
  115.     FW_VOLATILE(aboutDialogPresentation);
  116.     
  117.     short throwAt = 0;
  118.     FW_VOLATILE(throwAt);
  119.  
  120.     FW_TRY
  121.     {
  122.         ODTypeToken token = FW_CSession::Tokenize(ev, "Apple:ODF:Presentation:About");
  123.         aboutDialogPresentation = new FW_CPrivAboutPresentation(ev, part, token, id);
  124.     
  125.         throwAt = 1;
  126.         
  127.         part->PrivAddPresentation(aboutDialogPresentation);
  128.         
  129.         throwAt = 2;
  130.  
  131.         FW_CDialogFrame* aboutFrame = 
  132.             FW_CDialogFrame::NewModalDialog(ev, 
  133.                 part,                                    // Your part
  134.                 aboutDialogPresentation,                // Presentation
  135.                 FW_CPoint(kDialogWidth, kDialogHeight),    // Window size
  136.                 FW_kZeroPoint,                             // Window position
  137.                 FW_kStandardDialogPosition,                // Already made modal by NewModalDialog
  138.                 FW_CString(""));                        // Title for moveable dialog
  139.  
  140.         if (aboutFrame != NULL)
  141.         {
  142.             aboutFrame->SetDefaultButton(ev, kOKButtonID);
  143.             aboutFrame->GetWindow(ev)->Show(ev);
  144.         }
  145.         else 
  146.         {
  147.             part->PrivRemovePresentation(aboutDialogPresentation);
  148.             delete aboutDialogPresentation;
  149.         }
  150.     }
  151.     FW_CATCH_BEGIN
  152.     FW_CATCH_EVERYTHING()
  153.     {    
  154.         if (throwAt == 2)
  155.             part->PrivRemovePresentation(aboutDialogPresentation);
  156.         
  157.         delete aboutDialogPresentation;
  158.         
  159.         FW_THROW_SAME();
  160.     }
  161.     FW_CATCH_END
  162. }
  163.  
  164. //========================================================================================
  165. // class FW_CPrivAboutPresentation
  166. //========================================================================================
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // FW_CPrivAboutPresentation::FW_CPrivAboutPresentation
  170. //----------------------------------------------------------------------------------------
  171.  
  172. FW_CPrivAboutPresentation::FW_CPrivAboutPresentation(Environment *ev, 
  173.                                                     FW_CPart* thePart, 
  174.                                                     ODTypeToken presentationType,
  175.                                                     FW_ResourceID resourceID) :
  176.     FW_CPresentation(ev, thePart, NULL, presentationType, FW_kNoViewID, FW_kNoViewID),
  177.     fAboutID(resourceID)
  178. {
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // FW_CPrivAboutPresentation::~FW_CPrivAboutPresentation
  183. //----------------------------------------------------------------------------------------
  184.  
  185. FW_CPrivAboutPresentation::~FW_CPrivAboutPresentation()
  186. {
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // FW_CPrivAboutPresentation::PrivNewFrame
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CFrame* FW_CPrivAboutPresentation::PrivNewFrame(Environment *ev,
  194.                                                     ODFrame* odFrame, 
  195.                                                     FW_Boolean fromStorage)
  196. {
  197. FW_UNUSED(fromStorage);
  198.     return FW_NEW(FW_CAboutFrame, (ev, odFrame, this, GetPart(ev), fAboutID));
  199. }
  200.  
  201. //========================================================================================
  202. // class FW_CAboutFrame 
  203. //========================================================================================
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // FW_CAboutFrame::FW_CAboutFrame
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_CAboutFrame::FW_CAboutFrame(Environment* ev, 
  210.                             ODFrame* odFrame, 
  211.                             FW_CPresentation* presentation, 
  212.                             FW_CPart* part,
  213.                             FW_ResourceID resourceID)
  214.     : FW_CDialogFrame(ev, odFrame, presentation, part)
  215. {
  216.     FW_ResourceID iconID;
  217.     
  218.     // ----- Load the about resource
  219.     FW_PSharedLibraryResourceFile resFile(ev, part->GetPartInstance(ev));
  220.     
  221.     FW_PResource aboutResource(ev, resFile, resourceID, FW_kAboutResourceType);
  222.     FW_PResourceSink sink(ev, aboutResource);
  223.     FW_CReadableStream stream(sink);
  224.     stream >> iconID;
  225.  
  226.     stream >> fPartNameFontSize;
  227.     stream >> fPartNameFontStyle;
  228.     stream >> fPartNameFontName;
  229.     stream >> fPartName;
  230.  
  231.     stream >> fVersionFontSize;
  232.     stream >> fVersionFontStyle;
  233.     stream >> fVersionFontName;
  234.     stream >> fVersion;
  235.  
  236.     stream >> fCreditsFontSize;
  237.     stream >> fCreditsFontStyle;
  238.     stream >> fCreditsFontName;
  239.     stream >> fCredits;
  240.  
  241.     stream >> fOKString;
  242.     stream >> fButtonSize;
  243.  
  244.     // ----- Load the icon and set up the icon shape
  245.     FW_CRect bounds(kLargeMargin, kLargeMargin, kLargeMargin + FW_IntToFixed(32),  kLargeMargin + FW_IntToFixed(32));
  246.  
  247.     FW_CIcon icon(resFile, iconID, 32);
  248.     fIconShape = FW_NEW(FW_CIconShape ,(icon, bounds));
  249.  
  250.     FW_END_CONSTRUCTOR
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. // FW_CAboutFrame::~FW_CAboutFrame
  255. //----------------------------------------------------------------------------------------
  256.  
  257. FW_CAboutFrame::~FW_CAboutFrame()
  258. {
  259.     FW_START_DESTRUCTOR
  260.  
  261.     delete fIconShape;
  262. }
  263.  
  264. #ifdef FW_BUILD_MAC
  265. //----------------------------------------------------------------------------------------
  266. // FW_CAboutFrame::FacetAdded
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void FW_CAboutFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  270. {
  271.     FW_CDialogFrame::FacetAdded(ev, facet, facetCount);
  272.     
  273.     if (facetCount == 1)
  274.     {
  275.         ODPlatformWindow platformWindow = facet->GetWindow(ev)->GetPlatformWindow(ev);
  276.         
  277.         WCTabHandle newColorTable = (WCTabHandle)FW_CMemoryManager::AllocateSystemHandle
  278.                                                                     (8+sizeof(ColorSpec));
  279.         (*newColorTable)->ctSize = 0;
  280.         (*newColorTable)->ctTable[0].value = wContentColor;
  281.         (*newColorTable)->ctTable[0].rgb = FW_CColor(FW_kRGBLightGray);
  282.         ::SetWinColor(platformWindow, newColorTable);
  283.     }
  284. }
  285. #endif
  286.  
  287. //----------------------------------------------------------------------------------------
  288. // FW_CAboutFrame::Draw
  289. //----------------------------------------------------------------------------------------
  290.  
  291. void FW_CAboutFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  292. {
  293.     // ----- Set drawing contect for the CFrame
  294.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  295.     
  296.     // ----- Draw the Icon -----
  297.     fIconShape->Render(vc);
  298.     
  299.     // ----- Draw the lines -----
  300.     FW_CInk lineColor(FW_kRGBDarkGray);
  301.     FW_Fixed pos = kLargeMargin+kIconSize+kSmallMargin;
  302.     FW_CLineShape::RenderLine(vc, 
  303.                             FW_CPoint(pos, kLargeMargin),
  304.                             FW_CPoint(pos, kDialogHeight - kLargeMargin),
  305.                             lineColor);
  306.     FW_CLineShape::RenderLine(vc, 
  307.                             FW_CPoint(kLargeMargin, pos),
  308.                             FW_CPoint(kDialogWidth - kLargeMargin, pos),
  309.                             lineColor);
  310.     
  311.     // ----- Draw the Part Name -----
  312.     FW_CInk standardInk(FW_kNormalTextInk);
  313.     
  314.     FW_CFont partNameFont(FW_GetTimesFontName(), FW_kBold, FW_IntToFixed(24));
  315.     FW_CTextShape::RenderText(vc, 
  316.                             fPartName, 
  317.                             FW_CPoint(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin, kLargeMargin+kIconSize), 
  318.                             FW_CFont(fPartNameFontName, fPartNameFontStyle, fPartNameFontSize),
  319.                             FW_kTextAlignLeft+FW_kTextAlignBaseLine,
  320.                             standardInk);
  321.  
  322.     // ----- Draw the Version -----
  323.     FW_CTextShape::RenderText(vc, 
  324.                             fVersion, 
  325.                             FW_CPoint(kDialogWidth-kLargeMargin, kLargeMargin+kIconSize), 
  326.                             FW_CFont(fVersionFontName, fVersionFontStyle, fVersionFontSize),
  327.                             FW_kTextAlignRight+FW_kTextAlignBaseLine,
  328.                             standardInk);
  329.  
  330.     // ----- Draw the user Credits -----
  331.     FW_CRect descriptionBox(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
  332.                           kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
  333.                           kDialogWidth - kLargeMargin,
  334.                           kDialogHeight - kLargeMargin - kButtonHeight - kSmallMargin);
  335.     FW_CTextBoxShape::RenderTextBox(vc, 
  336.                             fCredits, 
  337.                             descriptionBox, 
  338.                             FW_CFont(fCreditsFontName, fCreditsFontStyle, fCreditsFontSize),
  339.                             FW_kTextBoxJustifyLeft+FW_kTextBoxJustifyTop+FW_kTextBoxWordWrap,
  340.                             standardInk);
  341.  
  342.     // ----- Draw the ODF Copyright -----
  343.     FW_CString odfCopyRight;
  344.     ::FW_PrivLoadODFString(ev, FW_kODFCopyright, odfCopyRight);
  345.     FW_CRect copyrightBox(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
  346.                           kDialogHeight - kLargeMargin - kButtonHeight,
  347.                           kDialogWidth - kLargeMargin - kButtonWidth,
  348.                           kDialogHeight - kLargeMargin);
  349.     FW_CTextBoxShape::RenderTextBox(vc, 
  350.                             odfCopyRight, 
  351.                             copyrightBox, 
  352.                             FW_CFont("geneva", FW_kPlain, FW_IntToFixed(9)),
  353.                             FW_kTextBoxJustifyLeft+FW_kTextBoxJustifyTop+FW_kTextBoxWordWrap,
  354.                             standardInk);
  355.                             
  356. }
  357.  
  358. //----------------------------------------------------------------------------------------
  359. // FW_CAboutFrame::CreateSubViews
  360. //----------------------------------------------------------------------------------------
  361.  
  362. void FW_CAboutFrame::CreateSubViews(Environment* ev)
  363. {        
  364.     if (fButtonSize == FW_kZeroPoint)
  365.         fButtonSize.Set(kButtonWidth, kButtonHeight);    // use default size
  366.  
  367.     // ----- Create the OK button
  368.     FW_CRect buttonRect(kDialogWidth - kLargeMargin - fButtonSize.x,
  369.                         kDialogHeight - kLargeMargin - fButtonSize.y,
  370.                         kDialogWidth - kLargeMargin,
  371.                         kDialogHeight - kLargeMargin);
  372.     FW_CButton* okButton = FW_NEW(FW_CButton, (ev, this, buttonRect, kOKButtonID, 
  373.                                         FW_kPushButton, fOKString));
  374. }
  375.  
  376. //----------------------------------------------------------------------------------------
  377. // FW_CAboutFrame::DoAdjustMenus
  378. //----------------------------------------------------------------------------------------
  379.  
  380. FW_Handled FW_CAboutFrame::DoAdjustMenus(Environment *ev, FW_CMenuBar* menuBar, 
  381.                                     FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  382. {
  383. FW_UNUSED(hasMenuFocus);
  384.     if (isRoot)
  385.         menuBar->EnableCommand(ev, kODCommandAbout, FALSE);
  386.  
  387.     return FW_kNotHandled;
  388. }
  389.  
  390. //----------------------------------------------------------------------------------------
  391. //    FW_CAboutFrame::HandleNotification
  392. //----------------------------------------------------------------------------------------
  393.  
  394. void FW_CAboutFrame::HandleNotification(Environment *ev, const FW_CNotification& notification)
  395. {
  396.     FW_CPresentation* presentation = GetPresentation(ev);
  397.     FW_CPart* part = GetPart(ev);
  398.     
  399.     // Close and delete the dialog on OK
  400.     FW_CDialogFrame::HandleNotification(ev, notification);
  401.     
  402.     part->PrivRemovePresentation(presentation);
  403.     delete presentation;
  404. }
  405.